package com.zhonggong.empConsumer.dao.impl;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import com.zhonggong.empConsumer.dao.ConsumerDao;
import com.zhonggong.network.emp.model.Emp;

public class ConsumerDaoImpl implements ConsumerDao{
	public Logger logger=LogManager.getLogger(ConsumerDaoImpl.class);
   
	public void add(Emp emp) {
		try {
			File file = new File("D:\\test.txt");
            BufferedWriter bw = new BufferedWriter(new FileWriter(file));
            bw.write(emp.getName()+" " + emp.getGongzi() +" "+emp.getBumen());
            bw.write("\r\n");
            bw.flush();
            bw.close();
        } catch (IOException e) {
            e.printStackTrace();
	}
	}
   
	public void writefile(String filename, String text) {
    	File file = new File(filename);
    	try {
    		FileWriter fileWriter = new FileWriter(file);
    		fileWriter.write(text);
    		fileWriter.close();
    		logger.info("写入成功！");
    	} catch (FileNotFoundException e) {
    		logger.info("该文件不存在！");
    		e.printStackTrace();
    	} catch (IOException e) {
    		logger.info("写入失败！");
    		e.printStackTrace();
    	}
    }
}

